from typing import Optional
from intelli_port.config import load_settings
from neo4j import GraphDatabase

_driver = None


def get_neo4j():
    global _driver
    s = load_settings()
    if not s.neo4j_uri:
        return None
    if _driver is None:
        try:
            _driver = GraphDatabase.driver(s.neo4j_uri)
        except Exception:
            _driver = None
    return _driver